<?php

namespace longhu\library;

use PhpAmqpLib\Connection\AMQPStreamConnection;
use think\facade\Config;

class SimpleMQBase
{
    protected function getConfig()
    {
        $config = Config::get('rabbitmq.AMQP');
        if(empty($config)){
            throw new \Exception("rabbitmq AMQP is null");
        }
        return $config;
    }

    public function getConfigDefail($name = '')
    {
        if(empty($name)){
            throw new \Exception("name is not null");
        }
        $defail = Config::get('rabbitmq.' . $name . '_queue');
        return $defail;
    }

    public function shutdown($channel, $connection)
    {
        $channel->close();
        $connection->close();
    }

    protected function connectRabbitMQ()
    {
        try {
            $connection = new AMQPStreamConnection("192.168.110.128",5672,"admin","123456");
            return  $connection;
        }catch (\Exception $exception){
            throw new \Exception("RabbitMQ链接失败！".$exception->getMessage());
        }
    }
}